﻿@{
    Bundle("jquery_validate");
    Bundle("jquery_timepicker");
}

<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('@ID("#form")').validate({
            rules: {
                catalogItemName: {
                    required: true
                },
                sellerName: {
                    required: true
                },
                sku: {
                    required: true
                }
            }
        });
        jQuery('@ID("#txt_catalogItem")').autocomplete({
            source: function (request, response) {
                jQuery.post('@Html.Raw(Url.Action(Loc.Act("Autocomplete").Ctrl("Item").Area("Catalog")))', request, response);
            },
            minLength: 3,
            select: function (event, ui) {
                jQuery('@ID("#hidden_catalogItem")').val(ui.item.id);
            }
        });
        jQuery('@ID("#txt_seller")').autocomplete({
            source: function (request, response) {
                jQuery.post('@Html.Raw(Url.Action(Loc.Act("Autocomplete").Ctrl("Seller")))', request, response);
            },
            minLength: 3,
            select: function (event, ui) {
                jQuery('@ID("#hidden_seller")').val(ui.item.id);
            }
        });
        jQuery('@ID("#txt_available_from")').datetimepicker();
        jQuery('@ID("#txt_available_to")').datetimepicker();
    });
</script>
<form id="@ID("form")" action="@Url.Action(Loc.Act("Create").Ctrl("SalesItem"))" method="post">
    <input type="hidden" name="flags" value="None" />
    <table>
        <tr>
            <td>
                <label>@T(Res.Name("Seller"))</label>
            </td>
            <td>
                <input id="@ID("hidden_seller")" type="hidden" name="sellerID" />
                <input id="@ID("txt_seller")" type="text" name="sellerName" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("CatalogItem"))</label>
            </td>
            <td>
                <input id="@ID("hidden_catalogItem")" type="hidden" name="catalogItemID" />
                <input id="@ID("txt_catalogItem")" type="text" name="catalogItemName" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.In("Common").Of("Vocab").Name("SKU"))</label>
            </td>
            <td>
                <input type="text" name="sku" value="@Guid.NewGuid()" maxlength="100" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("Price"), JDM.String(Svc.Localization.Currency.Code))</label>
            </td>
            <td>
                <input type="text" name="price" value="@Svc.Price(Decimal.Zero)" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("AvailableFrom"))</label>
            </td>
            <td>
                <input id="@ID("txt_available_from")" type="text" name="availableFrom" value="@Svc.DateTime(DateTime.UtcNow)" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.Name("AvailableTo"))</label>
            </td>
            <td>
                <input id="@ID("txt_available_to")" type="text" name="availableTo" value="@Svc.DateTime(DateTime.UtcNow.AddMonths(1))" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.In("API").Of("Enum").Of("SalesItemFlags").Name("Active"))</label>
            </td>
            <td>
                <input type="checkbox" name="flags" value="Active" />
            </td>
        </tr>
        <tr>
            <td>
                <label>@T(Res.In("API").Of("Enum").Of("SalesItemFlags").Name("VariablePricing"))</label>
            </td>
            <td>
                <input type="checkbox" name="flags" value="VariablePricing" />
            </td>
        </tr>
    </table>
    <ul class="bar toolbar">
        <li><button class="button" type="submit">@T(Res.In("Common").Of("Act").Name("Submit"))</button></li>
    </ul>
</form>